/**
 * 
 */
package com.star.encryption;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @ClassName: KeyUtil
 * @Description: TODO
 * @author starhq
 * @createtime 2014年11月28日 下午6:01:39
 * @email : jian.wang@shinsoft.net
 * @modify by TODO
 * @resaon
 * @edittime
 * @version 1.0
 * @copyright shinsoft
 */
public class KeyUtil {

	@SuppressWarnings("resource")
	public static byte[] readKey(String fileName) throws IOException {
		File file = new File(fileName);
		long len = file.length();
		byte data[] = new byte[(int) len];
		FileInputStream fin = new FileInputStream(file);
		int r = fin.read(data);
		if (r != len)
			throw new IOException("Only read " + r + " of " + len + " for "
					+ file);
		fin.close();
		return data;
	}

	public static void writeKey(String fileName, byte[] data)
			throws IOException {
		FileOutputStream fout = new FileOutputStream(fileName);
		fout.write(data);
		fout.close();
	}
}
